﻿<!DOCTYPE HTML>
<html>
<head th:include="fragments/_header :: _head('管理员列表')"></head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 管理员列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">

	<div class="cl pd-5 bg-1 bk-gray">
		<span class="l">
			<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
			<a href="javascript:;" onclick="add('添加管理员','/admin/add','700','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加管理员</a>
		</span>
		<span class="r">共有数据：<strong th:text="${page.total}">0</strong> 条</span>
	</div>
	<div class="text-c mt-20">
		<form action="/admin/list" id="searchForm">
			<input type="text" class="input-text" style="width:250px" placeholder="输入管理员名称" id="realName" name="realName">
			<input type="hidden" name="page" id="page" th:value="${page.current}">
			<button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
		</form>
	</div>
	<div class="dataTables_wrapper no-footer  mt-20">
		<table class="table table-border table-bordered table-bg">
			<thead>
				<tr>
					<th scope="col" colspan="8">管理员列表</th>
				</tr>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="150">姓名</th>
					<th width="150">登录名</th>
					<th width="90">手机</th>
					<th width="150">邮箱</th>
					<th width="130">加入时间</th>
					<th width="100">是否已启用</th>
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody>
				<tr class="text-c"  th:each="admin:${page.records}">
					<td><input type="checkbox"  th:value="${admin.id}" name="id"></td>
					<td th:text="${admin.realName}">admin</td>
					<td th:text="${admin.loginName}">admin</td>
					<td th:text="${admin.mobile}">13000000000</td>
					<td th:text="${admin.mobile}">admin@mail.com</td>
					<td  th:text="${#dates.format(admin.createDate, 'yyyy-MM-dd HH:mm:ss')}">2014-6-11 11:11:42</td>
					<td class="td-status" th:if="${admin.status eq 1}"><span class="label label-success radius">已启用</span></td>
					<td class="td-status" th:if="${admin.status ne 1}"><span class="label radius">已停用</span></td>
					<td class="td-manage">
						<a style="text-decoration:none" class="btn btn-danger radius" th:aid="${admin.id}" href="javascript:;" th:if="${admin.status eq 1}" onclick="stop(this)"  title="停用">停用</a>
						<a style="text-decoration:none" class="btn btn-primary radius" th:aid="${admin.id}" href="javascript:;" th:if="${admin.status ne 1}" onclick="start(this)" title="启用">启用</a>
						<a style="text-decoration:none" class="btn btn-primary radius" th:aid="${admin.id}" href="javascript:;" onclick="edit('管理员编辑','/admin/add',this,'700','500')" title="编辑">编辑</a>
						<a style="text-decoration:none" class="btn btn-danger radius" th:aid="${admin.id}" href="javascript:;" onclick="del(this)" title="删除">删除</a>
					</td>
				</tr>
			</tbody>
		</table>
		<div th:replace="fragments/_page :: pageBar(${page})"></div>
		<div th:replace="fragments/_page :: pagination(${page})"></div>
	</div>
</div>
<div th:include="fragments/_footer :: _footer"></div>
<script th:replace="fragments/_page :: pageScript"></script>
<script type="text/javascript" src="/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript">

/*管理员-增加*/
function add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-删除*/
function del(obj){
	layer.confirm('确认要删除吗？',function(index){
        var id = $(obj).attr("aid");
        $.post("/admin/delete", {ids: id}, function (result) {
            if (result.success) {
                $(obj).parents("tr").remove();
                layer.msg('已删除!',{icon:1,time:1000});
            } else {
                layer.msg(result.msg, {icon: 2, time: 1000});
            }
        });
	});
}

/*管理员-编辑*/
function edit(title,url,obj,id,w,h){
    var id = $(obj).attr("aid");
    layer_show(title, url + "?id=" + id, w, h);
}
/*管理员-停用*/
function stop(obj,id){
    var id = $(obj).attr("aid");
    layer.confirm('确认要停用吗？', function (index) {
        $.post("/admin/disable", {id: id}, function (result) {
            if (result.success) {
                window.location.reload();
            } else {
                layer.msg(result.msg, {icon: 2, time: 1000});
            }
        });
    });
}

/*管理员-启用*/
function start(obj,id){
    var id = $(obj).attr("aid");
    layer.confirm('确认要启用吗？', function (index) {
        $.post("/admin/enable", {id: id}, function (result) {
            if (result.success) {
                window.location.reload();
            } else {
                layer.msg(result.msg, {icon: 2, time: 1000});
            }
        });
    });
}

function datadel() {
    layer.confirm('确认要删除选中数据吗？', function (index) {
        var id = [];
        $('input[name="id"]:checked').each(function () {
            id.push($(this).val());
        });
        $.ajax({
            type: "post", url: "/admin/delete", traditional: true,
            data: {ids: id},
            dataType: "json",
            success: function (result) {
                if (result.success) {
                    window.location.reload();
                } else {
                    layer.msg(result.msg, {icon: 2, time: 1000});
                }
            }
        });
    });
}
</script>
</body>
</html>